package com.hailian.fintech.hlbackingserver.web;


import com.github.pagehelper.PageInfo;
import com.hailian.fintech.hlbackingserver.entity.Account;
import com.hailian.fintech.hlbackingserver.service.IAccountService;
import com.hailian.fintech.hlcomm_interfaceserver.entity.POJO;
import com.hailian.fintech.hlcomm_interfaceserver.result.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wk
 * @since 2020-05-30
 */
@RestController
@RequestMapping("/account")
public class AccountController {
   /* @InitBinder
    public void initBinder(WebDataBinder binder, WebRequest request) {
        //转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
    }*/
    @Autowired
    private IAccountService iAccountService;

    /**
     * 通过uid分页查询账户明细
     * @param uid
     * @param pageSize
     * @param pageNum
     * @param pojo
     * @return
     */
    @RequestMapping("getByUid")
    public Object getByUid(Integer uid, @RequestParam(defaultValue = "3") Integer pageSize, @RequestParam(defaultValue = "1") Integer pageNum, POJO pojo
    ){
        //List<Account> accounts = iAccountService.getByUid(uid);
        PageInfo info = iAccountService.getByUid(uid,pageSize,pageNum,pojo);
        return new ResultInfo().success(info);
    }

    /**
     * 添加账户明细
     * @param account
     * @return
     */
    @RequestMapping("addAccount")
    public Object addAccount(@RequestBody Account account){
        account.setOperation_time(new SimpleDateFormat("yy-MM-dd").format(new Date()));
        boolean flag  = iAccountService.saveOrUpdate(account);
        return new ResultInfo().success(flag);
    }
    /**
     * 查找{提现}账户明细，转入提现表
     * @param
     * @return
     */
    @RequestMapping("selectTiXianAccount")
    public List selectTiXianAccount(@RequestParam("operationType") String operationType){
        List<Account> accountList = iAccountService.selectTiXianAccount(operationType);
        return accountList;
    }

    /**
     * 查找{提现}账户明细，转入提现表
     * @param
     * @return
     */
    @RequestMapping("selectToAddJiaoYi")
    public List selectToAddJiaoYi(@RequestParam("status") String status){
        List<Account> accountList = iAccountService.selectToAddJiaoYi(status);
        return accountList;
    }

    /**
     * 提现审核通过，账户明细更改
     * @param id
     * @return
     */
    @RequestMapping("passAccount")
    public Object passAccount(@RequestParam("id") Integer id){
        Account account = iAccountService.getById(id);
        account.setState("审核通过");
        boolean flag  = iAccountService.saveOrUpdate(account);
        return new ResultInfo().success(flag);
    }



}

